package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.PurchaseList;
import com.atguigu.jxc.service.PurchaseListGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @author fenge
 */
@RequestMapping("purchaseListGoods")
@Controller
public class PurchaseListGoodsController {

    @Autowired
    private PurchaseListGoodsService purchaseListGoodsService;

    @PostMapping("save")
    @ResponseBody
    public ServiceVO save(PurchaseList purchaseList, String purchaseListGoodsStr, HttpSession session){
        purchaseListGoodsService.save(purchaseList,purchaseListGoodsStr,session);
        return new ServiceVO(100,"请求成功");
    }

    @PostMapping("list")
    @ResponseBody
    public Map<String,Object> list(String purchaseNumber, Integer supplierId, Integer state, String sTime, String eTime){
        return purchaseListGoodsService.list(purchaseNumber,supplierId,state,sTime,eTime);
    }

    @PostMapping("goodsList")
    @ResponseBody
    public Map<String,Object> goodsList(Integer purchaseListId){
        return purchaseListGoodsService.goodsList(purchaseListId);
    }

    @PostMapping("delete")
    @ResponseBody
    public ServiceVO delete(Integer purchaseListId){
        purchaseListGoodsService.delete(purchaseListId);
        return new ServiceVO(100,"请求成功");
    }

    @PostMapping("updateState")
    @ResponseBody
    public ServiceVO updateState(Integer purchaseListId){
        purchaseListGoodsService.updateState(purchaseListId);
        return new ServiceVO(100,"请求成功");
    }

    @PostMapping("count")
    @ResponseBody
    public String count(String sTime, String eTime ,Integer goodsTypeId, String codeOrName){
        return purchaseListGoodsService.count(sTime,eTime,goodsTypeId,codeOrName);
    }
}
